import { AddFormatFunc, FormatFunc, importRuleType, importVarRuleType } from "../types";

/** formatImportVar */
const FMIV = function (FMC: FormatFunc, rule: importVarRuleType): string {
	return `${FMC(rule[0])}${rule[1].length === 0 ? "" : ` as ${FMC(rule[1])}`}`;
};

AddFormatFunc<importRuleType>({

	type: "IMPORT",

	handle: (rule, FMC) => {
		return `import ${rule[1].length === 0 ? "" : `${rule[1][0].length === 0 ? "" : FMIV(FMC, rule[1][0])}${rule[1][0].length > 0 && rule[1][1].length > 0 ? ", " : ""}${rule[1][1].length === 0 ? "" : `{ ${rule[1][1].map(item => FMIV(FMC, item)).join(", ")} }`} from `}${FMC(rule[2])};`;
	},

})
